@extends('back.adminbase')
@section('content')
    <section class="hbox stretch">
        @include("back.public.left")
        <aside>
            <section class="vbox">
                <header class="header bg-white b-b clearfix">
                    <form class="talbe-search" method="get" action="{{url('back/book')}}">
                        <div class="row m-t-sm">
                            <div class="col-sm-9 m-b-xs" style="margin-top: 10px;color: #49A33C">
                                三级目录
                                <a role="button" class="btn btn-sm label-danger plhk" data-back="{{url('back/book/plhkThirdCollect')}}">批量回库
                                </a>
                            </div>
                            <div class="col-sm-3 m-b-xs">
                                <div class="btn-group pull-right">
                                    <a role="button" class="btn btn-info btn-sm " title="返回" href="{{url('back/book/secCollect/'.$iid)}}">
                                        <i class="glyphicon glyphicon-arrow-left"></i>&nbsp;返回
                                    </a>
                                </div>
                            </div>
                        </div>
                    </form>
                </header>
                <section class="scrollable  wrapper w-f">
                    <section class="panel panel-default">
                        <div class="table-responsive">
                            <table class="table table-hover m-b-none entity-view" data-path="/attendance/count/countDetail/id/{0}">
                                <thead>
                                <tr>
                                    <th style="text-align: center;width: 50px"><input type="checkbox" value="" class="quan"></th>
                                    <th style="text-align: center;width: 50px">序号</th>
                                    <th style="text-align: center;width: 50px">条形码</th>
                                    <th style="text-align: center;width: 50px">RFID编码</th>
                                    <th style="text-align: center;width: 100px">售价</th>
                                    <th style="text-align: center;width: 80px">租金</th>
                                    <th style="text-align: center;width: 130px">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach ($res as $k=>$v)
                                    <tr>
                                        <td style="text-align: center;"><input name="hk" type="checkbox" value="{{$v->SerialNo}}" class="xuan"></td>
                                        <td style="text-align: center;">{{$limit*($res->currentPage()-1)+$k+1}}</td>
                                        <td style="text-align: center;">{{$v->BarCode}}</td>
                                        <td style="text-align: center;">{{$v->rUID}}</td>
                                        <td style="text-align: center;">{{$v->sold_price}}</td>
                                        <td style="text-align: center;">{{$v->rent_price}}</td>
                                        <td style="text-align: center">
                                            <a href="{{ url('back/book/editThirdCollect/'.$v->SerialNo)}}" class="label label-success">编辑</a>
                                            <a data-back="{{ url('back/book/xjThirdCollect/'.$v->SerialNo)}}" class="xj label label-danger">回库</a>
                                            {{--<a href="{{ url('back/book/sjThirdCollect/'.$v->SerialNo)}}" class="label label-info">上架</a>--}}
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                    </section>
                    <div>书籍总量：{{$count}}</div>
                </section>

            </section>
        </aside>
    </section>

@endsection

@section('addscript')
    <script>
        $(function(){
            $(".quan").click(
                    function(){
                        if(this.checked==true){
                            $(".xuan").prop("checked", true);
                        }else{
                            $(".xuan").prop('checked', false);
                        }
                    }
            );
            var a = new Array();
            $(".plhk").click(function(){
                $("input[name='hk']:checked").each(function(k,v){
                    a[k] = $(this).val();
                });
                if (a.length==0) {
                    layer.alert("尚未选取！");
                    return false;
                }
                var url=$(this).attr("data-back");
                layer.confirm('您确定回库吗？', {
                    btn: ['确认','取消'] //按钮
                }, function() {
                    $.ajax({
                        'url': url,
                        'type': "post",
                        'data': {ids: a},
                        'dataType': 'json',
                        'success': function (data) {
                            if (data.success) {
                                layer.alert("回库成功！", function () {
                                    location.reload();
                                });
                            } else {
                                layer.alert(data.msg)
                            }
                        }
                    })
                }, function(){

                })
            })
            //二级联动
            $("#region_id").change(function() {
                var first = $(this).val();
                $.post("{{ url('admin/scenery/pull') }}",{pid:first},function(data){
                    if(data){
                        var region_id2 = $("#region_id2");
                        $("option",region_id2).remove();
                        var option = "<option value='0' selected=''> 选择城市</option>";
                        $.each(data,function(index,array){
                            option = option+"<option value='"+array['id']+"'>"+array['name']+"</option>";
                        });
                        region_id2.append(option);
                    }
                });
            });
            $(".del").click(function(){
                var url=$(this).attr("data-back");

                layer.confirm('您确定删除吗？', {
                    btn: ['确认','取消'] //按钮
                }, function(){
                    $.ajax({
                        'url':url,
                        'type':"get",
                        'dataType':'json',
                        'success':function(data){
                            if(data.success){
                                layer.alert("删除成功！",function(){
                                    location.reload();
                                });
                            }else{
                                layer.alert(data.msg)
                            }
                        }
                    })
                }, function(){

                })
            })
            $(".xj").click(function(){
                var url=$(this).attr("data-back");

                layer.confirm('您确定回库吗？', {
                    btn: ['确认','取消'] //按钮
                }, function(){
                    $.ajax({
                        'url':url,
                        'type':"post",
                        'dataType':'json',
                        'success':function(data){
                            if(data.success){
                                layer.alert("回库成功！",function(){
                                    location.reload();
                                });
                            }else{
                                layer.alert(data.msg)
                            }
                        }
                    })
                }, function(){

                })
            })
            $(".able").click(function(){
                var id=$(this).data("id");
                var able = $(this).data("able");
                if(able==1) {
                    able=2;
                } else {
                    able=1;
                }
                var mythis = $(this);
                $.ajax({
                    'url':"/admin/scenery/able/"+id+"/"+able,
                    'type':"get",
                    'dataType':'json',
                    'success':function(data){
                        if(data.success){
                            mythis.parent().find('.able').text(data.msg);
                            mythis.parent().find('.able').data('able',data.data);
                            if (data.data==1) {
                                var m ="启用"
                            } else {
                                var m ="禁用"
                            }
                            mythis.parent().parent().find('.status').text(m);
                        }else{
                            layer.alert(data.msg)
                        }
                    }
                })
            })
        });
    </script>
@endsection
